﻿using System;
using System.Data;
using System.Data.OracleClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Show_CellM : BasicPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CellList.DataSource = GetCellView();
            CellList.DataBind();
        }
    }

    private DataSet GetCellView()
    {
        string sqlstr = "AB_GetInfo_Pk.GetCell";
        OracleParameter[] _params = {
                new OracleParameter("v_County",OracleType.VarChar,20),
				new OracleParameter("V_Begin",OracleType.VarChar,100),
				new OracleParameter("V_End",OracleType.VarChar,100),
				new OracleParameter("V_Type",OracleType.VarChar,100),
				new OracleParameter("resultSet",OracleType.Cursor)
            };
        DateTime max = GetMaxDate(Request.QueryString["type"].ToString());
        _params[0].Value = Request.QueryString["county"].ToString();
        _params[1].Value = max.ToString("yyyy-MM-dd");
        _params[2].Value = max.AddDays(1).ToString("yyyy-MM-dd");
        _params[3].Value = Request.QueryString["type"].ToString();
        _params[4].Direction = ParameterDirection.Output;
        return OracleHelper.ExecuteDataSet(sqlstr, CommandType.StoredProcedure, _params);
    }

    private DateTime GetMaxDate(string argType)
    {
        string date;
        if (argType.Equals("3G"))
        {
            string sqlstr = "SELECT MAX(STARTED) FROM ALARM_TABLE_3G";
            date = OracleHelper.ExecuteScalar(sqlstr, CommandType.Text, null).ToString();
        }
        else
        {
            string sqlstr = "SELECT MAX(ALARM_START_TIME) FROM ALARM_TABLE_2G";
            date = OracleHelper.ExecuteScalar(sqlstr, CommandType.Text, null).ToString();
        }
        maxdate.InnerText = DateTime.Parse(date).ToString("yyyy-MM-dd 0点-HH:mm:ss");
        return DateTime.Parse(date);
    }
}
